package com.hp.goods_details_service.controller;

import com.hp.goods_details_service.service.GoodsDetailHTMLService;
import com.hp.goods_details_service.service.GoodsDetailsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.Map;

@Controller
public class GoodsDetailController {

    @Autowired
    private GoodsDetailsService goodsDetailsService;

    @Autowired
    private GoodsDetailHTMLService goodsDetailHTMLService;

    @RequestMapping("/goods-details/{spuId}.html")
    public String toPage(Model model,@PathVariable Long spuId){
        //查询商品详情相关的数据，绑定到页面中
        Map<String, Object> map = goodsDetailsService.getGoodsDetailsMap(spuId);
        model.addAllAttributes(map);
        //页面静态化
        goodsDetailHTMLService.createHtml(map,spuId);
        return "item";
    }
}
